<template>
    <div v-if="title != '' && student != []">
        <h2>{{ title }}</h2>
        {{ student.name }}-{{ student.age }}-{{ student.gender }}
    </div>
</template>

<script>
import eventBus from '../util/eventBus';

export default {
    data() {
        return {
            title: '',
            student: {}
        }
    },
    methods: {
        getMessage(data) {
            console.log('AppItem.vue getMessage');
            this.student = data.student;
            this.title = data.title;
        }
    },
    created() {
        console.log('AppItem.vue created');
        eventBus.on('sendData', this.getMessage); // 订阅事件sendData，触发后调用getMessage
    },
    unmounted() {
        console.log('AppItem.vue mounted');
        eventBus.off('sendData', this.getMessage); // 组件销毁的时候取消事件订阅
    },
}
</script>